<#import "/macro.ftl" as m>
<@m.page_header title='金融资产已发售产品' />
<div id="page-content-wrapper">
    <div id="page-title">
        <h3><a class="font-blue" href="/financialassets">金融资产</a> > 已发售产品</h3>
    </div>
    <div id="page-content">
		<div class="form-row">
			<div class="form-label col-md-4">
				<label>${financialAsset.name}</label>
			</div>
			<div class="form-label col-md-2">
				<label>金额：${financialAsset.amount?string(',##0.00')}元</label>
			</div>
			<div class="form-label col-md-2">
				<label>库存：${financialAsset.inventory?string(',##0.00')}元</label>
			</div>
			<div class="form-label col-md-4">
				<label>实时库存：${calculateInventory?string(',##0.00')}元</label>
			</div>
		</div>
		<div class="form-row">
			<div class="form-label col-md-4"></div>
			<div class="form-label col-md-2">
				<label>起息日：${financialAsset.valueDate?string('yyyy-MM-dd')}</label>
			</div>
			<div class="form-label col-md-2">
				<label>到日期：${financialAsset.dueDate?string('yyyy-MM-dd')}</label>
			</div>
			<div class="form-label col-md-4">
				<label>明细累计库存：${entryCalculateInventory?string(',##0.00')}元</label>
			</div>
		</div>
    	<table class="table">
	        <thead>
	            <tr>
	            	<th>名称</th>
	                <th class="text-right">总金额(元)<br />已售金额(元)</th>
	                <th class="text-right"></th>
	                <th>起息日</th>
	                <th>到期日</th>
	                <th>期限</th>
	                <th>开始销售时间<br />结束销售时间</th>
	                <th>操作</th>
	            </tr>
	        </thead>
	        <tbody>
	        	<#list financialAssetProducts as financialAssetProduct>
					<tr>
						<td>
							<a class="font-blue" onclick="showFinancialassetProduct( ${financialAsset.id}, ${financialAssetProduct.product.id} );">${financialAssetProduct.product.name}</a>
						</td>
						<td class="text-right">
							<#if financialAssetProduct.isNotSoldNotInStock>
								<span class="font-red mrg10R float-left">未售金额未入库</span>
							<#elseif financialAssetProduct.isOversellNotOutStock>
								<span class="font-red mrg10R float-left">超卖金额未出库</span>
							</#if>
							<span>${financialAssetProduct.product.totalAmount?string(',##0.00')}</span>
							<div>${financialAssetProduct.product.soldAmount?string(',##0.00')}</div>
						</td>
						<td class="text-right">
							
						</td>
		                <td>${financialAssetProduct.product.valueDate?string('yyyy-MM-dd')}</td>
		                <td>
		                	<span>${financialAssetProduct.product.dueDate?string('yyyy-MM-dd')}</span>
		                	<#if financialAssetProduct.isPaymentCollectionNotInStock>
								<span class="font-red mrg10L">回款未入库</span>
							</#if>
						</td>
		                <td>${financialAssetProduct.product.term}</td>
		                <td>
		                	<#if financialAssetProduct.product.startTime??>${financialAssetProduct.product.startTime?string('yyyy-MM-dd HH:mm:ss')}</#if>
		                	<br />
		                	<#if financialAssetProduct.product.startTime??>${financialAssetProduct.product.endTime?string('yyyy-MM-dd HH:mm:ss')}</#if>
		                </td>
		                <td>
		                	<a href="/financialassetstockentries/add?financialAssetId=${financialAsset.id}&productId=${financialAssetProduct.product.id}" class="btn medium primary-bg">
			                    <span class="button-content">调整库存</span>
			                </a>
		             	</td>
		            </tr>
				</#list>    
	    	</tbody>
	    </table>
    </div>
</div>
<script>

function showFinancialassetProduct( financialassetId,  productId ){
	$.get( '/financialassets/' + financialassetId + '/products/' + productId, function( data ){
		var html = '<div id="dialog" class="hide" title="产品"><div class="mrg10A">' + data + '</div></div>';
		$( html ).dialog({
	        resizable:!0,
	        minWidth:550,
	        minHeight:300,
	        modal:!0,
	        dialogClass:"modal-dialog",
	        closeOnEscape:!0,
	        close : function() {
				$( this ).dialog( "destroy" );
			},
	        buttons: {
	            关闭: function() {
	            	$("#dialog").dialog("close");
	            }
			}
		});
	});
};

</script>